<template>
  <div class="splash-screen" :class="{ 'fade-out': startFadeOut }" v-show="visible">
    <div class="splash-content">
      <div class="logo-container">
        <div class="logo-circle">
          <img src="https://kingcola-icg-imgsite.pages.dev/file/1749797597269_favicon.ico" alt="Logo"
            class="logo-image" />
        </div>
        <div class="logo-text">KingCola-ICG Blog</div>
      </div>

      <div class="tech-particles">
        <div v-for="i in 20" :key="i" class="particle" :style="getRandomStyle()"></div>
      </div>

      <div class="loading-bar">
        <div class="loading-progress" :style="{ width: `${loadingProgress}%` }"></div>
      </div>

      <div class="tagline">探索技术的无限可能</div>

      <div class="scroll-indicator" v-show="loadingComplete">
        <span>向下滑动进入博客</span>
        <i class="el-icon-arrow-down bounce"></i>
      </div>
    </div>

    <div class="tech-grid">
      <div v-for="i in 16" :key="i" class="grid-item" :style="getGridStyle()"></div>
    </div>

    <div class="tech-circles">
      <div v-for="i in 5" :key="i" class="circle" :style="getCircleStyle()"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'SplashScreen',
  data() {
    return {
      visible: true,
      loadingProgress: 0,
      loadingComplete: false,
      startFadeOut: false,
      scrollListener: null
    }
  },
  mounted() {
    // 模拟加载进度
    this.simulateLoading();

    // 添加滚动监听
    this.scrollListener = this.handleScroll.bind(this);
    window.addEventListener('wheel', this.scrollListener);
    window.addEventListener('touchmove', this.scrollListener);

    // 禁止页面滚动
    document.body.style.overflow = 'hidden';
  },
  beforeDestroy() {
    // 移除事件监听
    window.removeEventListener('wheel', this.scrollListener);
    window.removeEventListener('touchmove', this.scrollListener);

    // 恢复页面滚动
    document.body.style.overflow = '';
  },
  methods: {
    simulateLoading() {
      const interval = setInterval(() => {
        this.loadingProgress += 2;
        if (this.loadingProgress >= 100) {
          clearInterval(interval);
          this.loadingComplete = true;
        }
      }, 30);
    },
    handleScroll(event) {
      if (this.loadingComplete && event.deltaY > 0) {
        this.dismissSplashScreen();
      }
    },
    dismissSplashScreen() {
      this.startFadeOut = true;
      setTimeout(() => {
        this.visible = false;
        document.body.style.overflow = '';
      }, 1000);
    },
    getRandomStyle() {
      const size = Math.floor(Math.random() * 10) + 5;
      const x = Math.floor(Math.random() * 100);
      const y = Math.floor(Math.random() * 100);
      const delay = Math.random() * 5;
      const duration = Math.random() * 10 + 10;

      return {
        width: `${size}px`,
        height: `${size}px`,
        left: `${x}%`,
        top: `${y}%`,
        animationDelay: `${delay}s`,
        animationDuration: `${duration}s`
      };
    },
    getGridStyle() {
      const delay = Math.random() * 2;
      const duration = Math.random() * 2 + 1;

      return {
        animationDelay: `${delay}s`,
        animationDuration: `${duration}s`
      };
    },
    getCircleStyle() {
      const size = Math.floor(Math.random() * 200) + 100;
      const x = Math.floor(Math.random() * 100);
      const y = Math.floor(Math.random() * 100);
      const delay = Math.random() * 3;
      const duration = Math.random() * 10 + 20;
      const opacity = Math.random() * 0.2 + 0.1;

      return {
        width: `${size}px`,
        height: `${size}px`,
        left: `${x}%`,
        top: `${y}%`,
        opacity: opacity,
        animationDelay: `${delay}s`,
        animationDuration: `${duration}s`
      };
    }
  }
}
</script>

<style lang="scss" scoped>
.splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: linear-gradient(135deg, #0a2463, #1e3a8a);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: opacity 1s ease;

  &.fade-out {
    opacity: 0;
  }
}

.splash-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  text-align: center;
  padding: 2rem;
}

.logo-container {
  margin-bottom: 2rem;
  animation: fadeInDown 1s ease;
}

.logo-circle {
  width: 120px;
  height: 120px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  box-shadow: 0 0 30px rgba(0, 150, 255, 0.5);
  position: relative;
  overflow: hidden;

  &::before {
    content: '';
    position: absolute;
    width: 150%;
    height: 150%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transform: rotate(45deg);
    animation: shine 3s infinite;
  }
}

.logo-image {
  width: 80px;
  height: 80px;
  object-fit: contain;
  animation: pulse 2s infinite;
}

.logo-text {
  font-size: 2rem;
  font-weight: bold;
  background: linear-gradient(90deg, #64b5f6, #2196f3, #0d47a1);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-top: 1rem;
  letter-spacing: 1px;
}

.loading-bar {
  width: 300px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  margin: 2rem 0;
  overflow: hidden;
}

.loading-progress {
  height: 100%;
  background: linear-gradient(90deg, #2196f3, #64b5f6);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.tagline {
  font-size: 1.2rem;
  opacity: 0.8;
  margin-bottom: 2rem;
  animation: fadeIn 2s ease;
}

.scroll-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 2rem;
  animation: fadeIn 1s ease;

  span {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    opacity: 0.7;
  }

  i {
    font-size: 1.5rem;
  }
}

.bounce {
  animation: bounce 2s infinite;
}

.tech-particles {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: -1;
}

.particle {
  position: absolute;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  animation: float infinite linear;
}

.tech-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  z-index: 1;
}

.grid-item {
  border: 1px solid rgba(64, 158, 255, 0.1);
  animation: pulse infinite ease-in-out;
}

.tech-circles {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 0;
}

.circle {
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(64, 158, 255, 0.2);
  animation: rotate infinite linear;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes bounce {

  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }

  40% {
    transform: translateY(-10px);
  }

  60% {
    transform: translateY(-5px);
  }
}

@keyframes float {
  0% {
    transform: translateY(0) rotate(0deg);
  }

  100% {
    transform: translateY(-100vh) rotate(360deg);
  }
}

@keyframes shine {
  0% {
    left: -100%;
  }

  100% {
    left: 100%;
  }
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 768px) {
  .logo-circle {
    width: 100px;
    height: 100px;
  }

  .logo-image {
    width: 70px;
    height: 70px;
  }

  .logo-text {
    font-size: 1.5rem;
  }

  .loading-bar {
    width: 250px;
  }
}
</style>